﻿//tabs=4
// --------------------------------------------------------------------------------
//
// ASCOM Video Driver - Simulator
//
// Description:	The settings of the Video Driver Simulator
//
// Author:		(HDP) Hristo Pavlov <hristo_dpavlov@yahoo.com>
//
// --------------------------------------------------------------------------------
//

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Configuration;
using ASCOM;
using ASCOM.DeviceInterface;
using Simulator.VideoCameraImpl;

/************************
 * Do not modify this file. Do not delete this empty class definition.
 * 
 * The purpose of this code is to attach the two attributes [SettingsProvider] and [DeviceId]
 * to the driver's Settings class. The settings class is automatically generated by
 * Visual Studio, so the attributes can't be added directly to the generated class.
 * 
 * Once these attributes are present on the Settings class, then Visual Studio's settings designer
 * can be used to manage driver settings and to bind settings directly to controls on
 * the Setup Dialog. Instead of being stored in the usual place, the
 * [SettingsProvider] attribute forces Visual Studio to use a custom settings provider
 * that is installed with the ASCOM Platform. The custom settings provider uses
 * ASCOM.Utilities.Profile as its underlying storage engine. The [DeviceId] attribute is
 * used by the SettingsProvider to configure ASCOM.Utilities.Profile to store settings against
 * the correct device profile.
 * **********************/

namespace ASCOM.Simulator.Properties
{
	public enum SiumulatedCameraType
	{
		AnalogueNonIntegrating,
		AnalogueIntegrating,
		Digital,
		VideoSystem
	}

	public enum AnalogueCameraFrameRate
	{
		PAL,
		NTSC
	}

	[SettingsProvider(typeof(ASCOM.SettingsProvider))]
	[ASCOM.DeviceId("ASCOM.Simulator.VideoCamera", DeviceName = "Video Camera and Recorder Simulator")]
	internal sealed partial class Settings
	{
		protected override void OnSettingChanging(object sender, SettingChangingEventArgs e)
		{
			base.OnSettingChanging(sender, e);

			if (e.SettingName == "SourceBitmapFilesLocation" &&
				!string.Equals(e.NewValue, SourceBitmapFilesLocation))
			{
				BitmapVideoPlayer.InvalidateBufferedVideoFrames();	
			}
		}

		internal void Reset(SiumulatedCameraType cameraType)
		{
			switch(cameraType)
			{
				case SiumulatedCameraType.AnalogueNonIntegrating:
					ResetAnalogueNonIntegratingDefaults();
					break;

				case SiumulatedCameraType.AnalogueIntegrating:
					ResetAnalogueIntegratingDefaults();
					break;

				case SiumulatedCameraType.Digital:
					ResetDigitalDefaults();
					break;

				case SiumulatedCameraType.VideoSystem:
					ResetVideoSystemDefaults();
					break;

				default:
					throw new ArgumentOutOfRangeException();
			}
		}

		private void ResetCommonDefaults()
		{
			VideoCaptureDeviceName = "Simulated Video Capture Device";
			SupportedActionsList = "SimulatedAction1#;SimulatedAction2";
			CameraFrameRate = AnalogueCameraFrameRate.PAL;
			SensorType = SensorType.Monochrome;
			Gains = string.Empty;
			PixelSizeX = 10;
			PixelSizeY= 10;
		}

		private void ResetAnalogueNonIntegratingDefaults()
		{
			ResetCommonDefaults();

			CameraType = SiumulatedCameraType.AnalogueNonIntegrating;
			SupportedExposuresList = "0.04";
			ExposureMin = 0.04;
			ExposureMax = 0.04;
			SensorName = "ICX285AL";
			BitDepth = 8;
			VideoFileFormat = "AVI";
			GainMin = 0;
			GainMax = 0;
			Gains = "";
			SupportsGainRange = false;
			Gammas = "";
		}

		private void ResetAnalogueIntegratingDefaults()
		{
			ResetCommonDefaults();

			CameraType = SiumulatedCameraType.AnalogueIntegrating;
			SupportedExposuresList = "0.04#;0.08#;0.16#;0.32#;0.64#;1.28#;2.56#;5.12#;10.24";
			ExposureMin = 0.04;
			ExposureMax = 10.24;
			SensorName = "ICX285AL";
			BitDepth = 8;
			VideoFileFormat = "AVI";
			GainMin = 0;
			GainMax = 37;
			Gains = "";
			SupportsGainRange = true;
			Gammas = "OFF (1.00)#;LO (0.45)#;HI (0.35)";
		}

		private void ResetDigitalDefaults()
		{
			ResetCommonDefaults();

			CameraType = SiumulatedCameraType.Digital;
			SupportedExposuresList = "0.033#;0.067#;0.133#;0.267#;0.533#;1#;2#;4#;8";
			ExposureMin = 0.033;
			ExposureMax = 8.0;
			SensorName = "ICX285AL";
			BitDepth = 14;
			VideoFileFormat = "FITS";
			GainMin = 0;
			GainMax = 32;
			Gains = "";
			SupportsGainRange = true;
			Gammas = "MIN (3.0)#;OFF#;LO#;HI#;MAX (0.25)";
		}

		private void ResetVideoSystemDefaults()
		{
			ResetCommonDefaults();

			CameraType = SiumulatedCameraType.VideoSystem;
			SupportedExposuresList = "0.033#;0.067#;0.133#;0.267#;0.533#;1#;2#;4#;8";
			ExposureMin = 0.033;
			ExposureMax = 8.0;
			SensorName = "ICX285AL";
			BitDepth = 12;
			VideoFileFormat = "ADV";
			GainMin = 0;
			GainMax = 0;
			SupportsGainRange = false;
			Gains = "0#;1#;2#;3#;4#;5#;6#;7#;8#;9#;10#;11#;12#;13#;14#;15#;16#;17#;18#;19#;20#;21#;22#;23#;24#;25#;26#;27#;";
			Gammas = "MIN (3.0)#;OFF#;1.333#;LO#;HI#;MAX(0.25)";
		}
	}
}
